home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWExcLib / Sources / FWExcLog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  4.9 KB  |  145 lines  |  [TEXT/MPS ]

  1. #ifdef FW_DEBUG
  2. // This entire file is for debugging only
  3. //========================================================================================
  4. //
  5. //    File:                FWExcLog.cpp
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #ifndef   FWPRIDEB_H
  15. #include "FWPriDeb.h"
  16. #endif
  17.  
  18. #ifndef   FWEXCLOG_H
  19. #include "FWExcLog.h"
  20. #endif
  21.  
  22. #ifndef   FWTRACE_H
  23. #include "FWTrace.h"
  24. #endif
  25.  
  26. #ifndef FWEXCDEF_H
  27. #include "FWExcDef.h"
  28. #endif
  29.  
  30. #ifndef FWDBGSTR_H
  31. #include "FWDbgStr.h"
  32. #endif
  33.  
  34. #ifdef FW_BUILD_MAC
  35. #pragma segment BEL
  36. #endif
  37.  
  38. //========================================================================================
  39. // CLASS _FW_CExceptionLog
  40. //========================================================================================
  41.  
  42. //----------------------------------------------------------------------------------------
  43. // _FW_CExceptionLog::Initialize
  44. //----------------------------------------------------------------------------------------
  45. void _FW_CExceptionLog::Initialize(FW_SPrivExceptionLog& globals)
  46. {
  47.     globals.gInitialized = 1;
  48. }
  49.  
  50. //----------------------------------------------------------------------------------------
  51. // _FW_CExceptionLog::StartLog
  52. //----------------------------------------------------------------------------------------
  53. // We increment the counter each time StartLog is called.
  54. // Logging is only enabled when the counter is above 0.
  55. // Logging requires tracing, so StartLog calls StartTrace.
  56. void _FW_CExceptionLog::StartLog()
  57. {
  58.     FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
  59.     globals.gLogEnabled++;
  60.     FW_PRIV_ASSERT(globals.gLogEnabled>0);    // if fails, StartLog called too many times!
  61.     globals.gTriggerCounter = 0;                // Reset the counter
  62.     FW_CTraceRuntime::StartTrace();
  63. }
  64.  
  65. //----------------------------------------------------------------------------------------
  66. // _FW_CExceptionLog::StopLog
  67. //----------------------------------------------------------------------------------------
  68. unsigned long _FW_CExceptionLog::StopLog()
  69. {
  70.     FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
  71.     FW_CTraceRuntime::StopTrace();
  72.     globals.gLogEnabled--;
  73.     FW_PRIV_ASSERT(globals.gLogEnabled>=0);    // if fails, StopLog called too many times!
  74.     return globals.gTriggerCounter;        
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // _FW_CExceptionLog::LogException
  79. //----------------------------------------------------------------------------------------
  80. void _FW_CExceptionLog::LogException(FW_ClassReference  exceptionClass)
  81. {
  82.     FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
  83.     if (globals.gLogEnabled == 0)
  84.         return;
  85.  
  86.     FW_CDebugStream * traceStream = FW_CPrivTraceTaskGlobals::GetTraceGlobals().gTraceStream;
  87.  
  88.     if (traceStream != NULL)
  89.     {
  90.         globals.gTriggerCounter++;
  91.         const char *name = exceptionClass->GetClassName();
  92.         (*traceStream) << "LOG: ";
  93.         (*traceStream) << globals.gTriggerCounter;
  94.         (*traceStream) << " Class " << name << EndLine;
  95.     }
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. // _FW_CExceptionLog::TriggerException
  100. //----------------------------------------------------------------------------------------
  101. void _FW_CExceptionLog::TriggerException(FW_ClassReference  exceptionClass, 
  102.                                   const _FW_CException  &theException)
  103. {
  104.     FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
  105.  
  106.     globals.gTriggerCounter++;
  107.  
  108.     FW_ClassReference triggerClass    = globals.gTriggerClass;
  109.  
  110.     //
  111.     //    If the Exception that is going to be triggered is not NULL, check if there is a 
  112.     //    match.  Else Check if the trigger point is the one we want.
  113.     //
  114.     if (triggerClass != NULL && triggerClass == exceptionClass)
  115.         FW_THROW(theException);
  116.     else if (globals.gTriggerPoint == globals.gTriggerCounter)
  117.         FW_THROW(theException);
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. // _FW_CExceptionLog::CauseException
  122. //----------------------------------------------------------------------------------------
  123. void _FW_CExceptionLog::CauseException(unsigned long triggerPoint)
  124. {
  125.     FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
  126.  
  127.     globals.gTriggerCounter = 0;
  128.     globals.gTriggerClass = 0;
  129.     globals.gTriggerPoint = triggerPoint;
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. // _FW_CExceptionLog::CauseException
  134. //----------------------------------------------------------------------------------------
  135. void _FW_CExceptionLog::CauseException(FW_ClassReference exceptionClass)
  136. {
  137.     FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
  138.  
  139.     globals.gTriggerCounter = 0;
  140.     globals.gTriggerClass = exceptionClass;
  141.     globals.gTriggerPoint = 0;
  142. }
  143.  
  144. #endif
  145.